package com.future.email.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 邮件控制器
 *
 * @author shiyong
 * 2021/5/24 9:55
 */
@RestController
@RequestMapping("/emailInfo")
public class EmailInfoController {
    /**
     * 发送邮件
     *
     * @param email 邮件地址
     * @return java.lang.String
     * @author shiyong
     * 2021/7/27 8:16
    */
    @PostMapping("/sendEmail")
    public String sendEmail(String email, HttpServletRequest request) {
        System.out.println("向" + email + "发送邮件");

        // 增加等待时间，用于测试熔断策略
//        try {
//            Thread.sleep(15000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        // 返回端口号，测试负载均衡
        int port = request.getServerPort();

        return email + "，端口：" + port;
    }
}
